using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

// 定义一个继承自Skill的类Dash_Skill
public class Dash_Skill : Skill
{
    [Header("Dash")]
    [SerializeField] private UI_SkillTreeSlot dashUnlockButton; // 冲刺技能解锁按钮
    public bool dashUnlocked { get; private set; } // 冲刺技能是否解锁

    [Header("Clone on Dash")]
    [SerializeField] private UI_SkillTreeSlot cloneOnDashUnlockButton; // 冲刺时释放幻影技能解锁按钮
    public bool cloneOnDashUnlocked { get; private set; }// 冲刺时释放幻影技能是否解锁

    [Header("Clone on arrival")]
    [SerializeField] private UI_SkillTreeSlot cloneOnArrivalButton; // 到达时释放幻影技能解锁按钮
    public bool cloneOnArrivalUnlocked { get; private set; } // 到达时释放幻影技能是否解锁

    // 重写UseSkill方法
    public override void UseSkill()
    {
        base.UseSkill();
    }

    // 重写Start方法
    protected override void Start()
    {
        base.Start();
        // 为解锁按钮添加点击事件监听器
        dashUnlockButton.GetComponent<Button>().onClick.AddListener(UnlockDash);
        cloneOnDashUnlockButton.GetComponent<Button>().onClick.AddListener(UnlockCloneOnDash);
        cloneOnArrivalButton.GetComponent<Button>().onClick.AddListener(UnlockCloneOnArrival);
    }

    // 继续游戏遍历一遍技能槽
    protected override void CheckUnlock()
    {
        UnlockDash();
        UnlockCloneOnDash();
        UnlockCloneOnArrival();
    }

    // 解锁冲刺技能
    private void UnlockDash()
    {
        if (dashUnlockButton.unlocked)
        {
            dashUnlocked = true; // 设置冲刺技能已解锁
        }
    }

    // 解锁冲刺时释放幻影技能
    private void UnlockCloneOnDash()
    {
        if (cloneOnDashUnlockButton.unlocked)
            cloneOnDashUnlocked = true; // 设置冲刺时释放幻影技能已解锁
    }

    // 解锁到达时释放幻影技能
    private void UnlockCloneOnArrival()
    {
        if (cloneOnArrivalButton.unlocked)
            cloneOnArrivalUnlocked = true; // 设置到达时释放幻影技能已解锁
    }

    // 冲刺开始释放幻影
    public void CloneOnDash()
    {
        if (cloneOnDashUnlocked)
        {
            SkillManager.instance.clone.CreateClone(player.transform, Vector3.zero); // 创建幻影
        }
    }

    // 冲刺结束释放幻影
    public void CloneOnArrival()
    {
        if (cloneOnArrivalUnlocked)
        {
            SkillManager.instance.clone.CreateClone(player.transform, Vector3.zero); // 创建幻影
        }
    }
}